package com.plian.Tools;

import com.alibaba.ttl.TransmittableThreadLocal;
import com.plian.Tools.pagedata.UserData;

public class TokenUtil {

    private static final TransmittableThreadLocal<UserData> contextHolder = new TransmittableThreadLocal<>();

    private TokenUtil(){}

    public static void setUserData(UserData userData){
        contextHolder.set(userData);
    }

    public static UserData getUserData(){
        return contextHolder.get();
    }


    public static String getTokenUserId() {
        UserData userData = getUserData();
        return userData != null ? userData.getUserId() : null;
    }
    public static String getTokenOrgId() {
        UserData userData = getUserData();
        return userData != null ? userData.getOrgId() : null;
    }

    public static String getCompetentOrganization() {
        UserData userData = getUserData();
        return userData != null ? userData.getCompetentOrganization() : null;
    }

    public static String getOfficeId() {
        UserData userData = getUserData();
        return userData != null ? userData.getOfficeId() : null;
    }

    public static void clearUserData(){
        contextHolder.remove();
    }

}
